<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="/layer/layer.js"></script>
</head>
<body>
<div id="addIcon">
    <form>

        <div class="col-sm-10" class="form-group">
            <label for="exampleInputEmail1">名字</label>
            <input class="form-control" id="exampleInputEmail1" placeholder="名字" v-model="iconInfo.name">
        </div>
        <div class="form-group">
            <label for="file" class="col-sm-2 control-label">图标缩略图（建议上传100*100或200*200的图片）：</label>
            <div class="col-sm-10">
                <input type="file" id="file" accept="image/*" class="form-control" name="file"/>
            </div>
        </div>

        <div class="form-group">
            <label for="orders" class="col-sm-2 control-label">orders</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="orders" v-model="iconInfo.orders">
            </div>
        </div>

        <div class="form-group">
            <label for="groupId" class="col-sm-2 control-label">服务类型</label>
            <div class="col-sm-10">
                <select name="pid" v-model="iconInfo.groupId" class="form-control">
                    <option class="form-control" id="groupId" v-for="g in groupList " v-bind:value="g.id">
                        {{g.name}}
                    </option>
                </select>
            </div>
        </div>

        <button type="button" class="btn btn-default" @click="addIcon">保存</button>
    </form>
</div>
<script>
    new Vue({
        el: "#addIcon",
        data: {
            iconInfo: {},
            groupList: []

        },
        created() {
            this.GroupList();
        },
        methods: {
            addIcon() {
                var vm = this;
                var formData=new FormData();
                var inputDOM=document.getElementById("file");
                var file=inputDOM.files[0];
                formData.append('file',file);
                formData.append('name',vm.iconInfo.name);
                formData.append("orders", vm.iconInfo.orders);
                formData.append("groupId", vm.iconInfo.groupId);
                $.ajax({
                    url:"add",
                    type:"post",
                    data:formData,
                    contentType:false,
                    processData:false,
                    async:false,
                    success:function (result) {
                        console.log(result)
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    }
                })

            },
            GroupList() {
                var vm = this;
                $.post("/group/groupList", {}, function (response) {
                    if (response.code == 200) {
                        vm.groupList = response.data;
                    }
                })
            }
        }

    })
</script>
</body>
</html>